const App = getApp();
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
var moment = require("../../utils/moment.min")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:"",
    carnumber:"",
    time:"",
    list:[],
    currentDate: new Date().getTime(),
    timeshow:false,
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } 
      if (type === 'month') {
        return `${value}月`;
      }
      return value;
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var type = wx.getStorageSync("type");
    console.log("type",type);
    this.setData({type:type})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var now = moment().format("YYYY-MM-DD");
    this.setData({time:now})
     this.getdata();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  myinfo(){
    console.log("ss");
    wx.redirectTo({
      url: '/pages/user/user'
    })
  },
  onInput(event) {
    console.log("date!!!!",event.detail);
    //var date = moment(event.detail).format("YYYY-MM-DD");

 
  },
  onClosedate() {
    this.setData({ timeshow: false });
  },
  onSelectdate(uitem) {
    console.log("fff",uitem)
    this.setData({
      time: moment(uitem.detail).format("YYYY-MM-DD"),
    });
    this.setData({ timeshow: false });
  },
  choosetime:function(){
    console.log("???")
    this.setData({timeshow:true})
  },
  onConfirm(event) {
    console.log("ss",event);
    this.setData({
      timeshow: false,
      time: this.formatDate(event.detail),
    });
  },
  getdata(){
    var that = this;
    var datestr = this.data.time;
    var carnumber = this.data.carnumber;
    var token = wx.getStorageSync('token');
    App._post_form('wxapi/car/list2', {
      token:token,datestr:datestr,carnumber:carnumber
    }, function(result) {

        if(result.status=="200"){
          that.setData({list:result.data})
        }
    });
  },
  setcarnumber:function(e){
    this.setData({carnumber: e.detail})
  },
  goinfo(e){
    var workid = e.currentTarget.dataset['id'];

    wx.navigateTo({
      url: '/pages/order/info?workid='+workid,
    })
  },
  gohome(){
    wx.navigateBack({ changed: true });
  },
  getScancode:function(){
    wx.scanCode({
     onlyFromCamera: true,
     success: (res) => {
       console.log(res)
        var code = res.result;
        var token = wx.getStorageSync('token');
        App._post_form('wxapi/check', {
          token:token,ordernum:code
        }, function(result) {
          
            if(result.status=="200"){
             Dialog.alert({
               title: '系统提示',
               message: '核验成功',
             }).then(() => {
               // on close
              
             });
            }else{
             Dialog.alert({
               title: '系统提示',
               message: result.message,
             }).then(() => {
               // on close
             });
            }
        });
       
     }
   })
 },
})